#include "ipc.h"
int main(int argc,char *argv[])
{
int rate;
if(argv[1] != NULL) rate = atoi(argv[1]);
else rate = 3;
buff_key = 101; 
buff_num = 1; 
cget_key = 103; 
cget_num = 1;
shm_flg = IPC_CREAT | 0644;
buff_ptr = (char *)set_shm(buff_key,buff_num,shm_flg);
cget_ptr = (int *)set_shm(cget_key,cget_num,shm_flg);
tobacco_key = 201;
glue_key = 202;
paper_key=203;
empty_key = 301;
mutex_key = 302;
sem_flg = IPC_CREAT | 0644; 
sem_val = buff_num;
empty_sem = set_sem(empty_key,sem_val,sem_flg);
sem_val = 0; 
glue_sem = set_sem(glue_key,sem_val,sem_flg);
while(1){
down(glue_sem);
sleep(rate);
printf("%d  1 smoke from Buffer[%d]\n",getpid(),*cget_ptr);
*cget_ptr = (*cget_ptr+1) % buff_num;
up(empty_sem);
}
return EXIT_SUCCESS;
}
